﻿@model RechercheEmplois.Models.Offre

@{
    ViewBag.Title = "Details";
}

<h2>Détails de l'offre</h2>
<hr />
<div>
    <div class="panel panel-success">
        <div class="panel-heading"><h3>@Model.Libelle</h3></div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-8">
                    <dl class="dl-horizontal">
                        <dt>
                            @Html.DisplayNameFor(model => model.Type)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Type)
                        </dd>

                        <dt>
                            Secteur
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Domaine.Libelle)
                        </dd>

                        <dt>
                            Recruiteur
                        </dt>

                        <dd>
                            @string.Join(" ", Model.Recruiteur.Nom, Model.Recruiteur.Prenom)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.Ville.Libelle)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Ville.Libelle)
                        </dd>
                        
                        <dt>
                            Région
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Ville.Provine.Libelle)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.NiveauEtude)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.NiveauEtude)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.Description)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Description)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.HoraireTravail)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.HoraireTravail)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.RenumHoraire)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.RenumHoraire) $
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.DebutContrat)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.DebutContrat)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.FinContrat)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.FinContrat)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.ExpMin)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.ExpMin) ans
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.Commentaire)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Commentaire)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.DateCreated)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.DateCreated)
                        </dd>

                    </dl>
                </div>
                <div class="col-md-4">
                    <a id="small-logo" href="/"></a>
                </div>
            </div>
        </div>
        <div class="panel-footer">
            <p>
                @Html.ActionLink("Back to List", "Index", null, new { @class = "btn btn-primary" })
                @if (ViewBag.UserType == "Administrator")
                {
                        if (Model.Valide == 0)
                        {
                            @Html.ActionLink("Valider", "Valider", "Offre", new { id = Model.ID }, new { @class = "btn btn-danger" })
                        }
                        else
                        {
                            @Html.ActionLink("Dé-valider", "Valider", "Offre", new { id = Model.ID }, new { @class = "btn btn-danger" })
                        }
                        @Html.ActionLink("Modifier", "Edit", "Offre", new { id = Model.ID }, new { @class = "btn btn-success" })
                        @Html.ActionLink("Supprimer", "Delete", "Offre", new { id = Model.ID }, new { @class = "btn btn-info" })
                }
                else if (ViewBag.UserType == "Internaute")
                {
                    <a class="btn btn-warning" onclick="saveOffre(@Model.ID);">Sauvegarder</a>
                    @Html.ActionLink("Postuler", "Create", "Postuler", new {offreID = Model.ID}, new {@class = "btn btn-success"})
                }
                else if (ViewBag.IsRecruiteur == true)
                {
                        @Html.ActionLink("Modifier", "Edit", "Offre", new { id = Model.ID }, new { @class = "btn btn-success" })
                        @Html.ActionLink("Supprimer", "Delete", "Offre", new { id = Model.ID }, new { @class = "btn btn-info" })
                }
            </p>
        </div>
    </div>
    
</div>

<script type="text/javascript">
    //Sauvegarder buttons click
    function saveOffre(id) {
        // e.preventDefault(); use this or return false
        $.ajax({
            url: "/Sauvegarde/Create",
            type: "post",
            data: "OffreID=" + id,
            success: function (result) {
                var response;
                if (result == 1) {
                    response = "Offre est sauvé succès!";
                }
                else if (result == 0) {
                    response = "Offre a été déjà sauvé!";
                } else {
                    response = "Utilisateur non identifié!";
                }
                var url = '/Offre/GetMessage?title=SaveInformation&body=' + encodeURI(response);
                $("#myModal").on("show.bs.modal", function (e) {
                    $(e.target).find('.modal-content').load(url);
                });
                $('#myModal').modal('show');
                $('#myModal').on('hidden.bs.modal', function () {
                    if (result == 1)
                        reloadPage();
                });
            },
            error: function () {
                alert("technique failure!");
            }
        });
    }
</script>